import 'package:flutter/material.dart';
import 'package:kxy_flutter_app/view/examination/exam_result/exam_result_body_widget.dart';
import 'package:kxy_flutter_app/view/examination/exam_result/exam_result_header_widget.dart';
import 'package:kxy_flutter_app/view/examination/view_model/exam_model.dart';
import 'package:provider/provider.dart';

class ExamResultView extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return ExamResultViewState();
  }
}

class ExamResultViewState extends State<ExamResultView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color.fromRGBO(240, 240, 240, 1),
      appBar: appbar(),
      body: Consumer<ExamModel>(
        builder: (cxt, examModel, child) {
          return body(examModel, context);
        },
      ),
    );
  }

  Widget body(ExamModel model, BuildContext context) {
    return Stack(
      children: [
        Column(
          children: [
            ExamReusltHeaderWidget(result: model.examResult),
            ExamResultBodyWidget(
              result: model.examResult,
              quesList: model.questionList,
            ),
            Container(
              height: 10,
              margin: EdgeInsets.symmetric(horizontal: 30),
              decoration: panelDecoration(Color.fromRGBO(250, 250, 250, 1)),
            ),
            Container(
              height: 8,
              margin: EdgeInsets.symmetric(horizontal: 40),
              decoration: panelDecoration(Color.fromRGBO(245, 245, 245, 1)),
            ),
          ],
        ),
        Positioned(
          top: 210,
          left: 10,
          child: Container(
            height: 20,
            width: 20,
            decoration: BoxDecoration(
              color: Color.fromRGBO(240, 240, 240, 1),
              shape: BoxShape.circle,
            ),
          ),
        ),
        Positioned(
          top: 210,
          right: 10,
          child: Container(
            height: 20,
            width: 20,
            decoration: BoxDecoration(
              color: Color.fromRGBO(240, 240, 240, 1),
              shape: BoxShape.circle,
            ),
          ),
        ),
      ],
    );
  }

  Decoration panelDecoration(Color color, {bool withTopRadius = false}) {
    return BoxDecoration(
      color: color,
      borderRadius: BorderRadius.vertical(
        top: Radius.circular(withTopRadius ? 12 : 0),
        bottom: Radius.circular(12),
      ),
      boxShadow: [
        BoxShadow(
          blurRadius: 3,
          offset: Offset(1, 0),
          color: Color.fromRGBO(225, 225, 225, 1),
        ),
      ],
    );
  }

  Widget appbar() {
    return AppBar(
      title: Text('答题报告', style: TextStyle(color: Colors.white)),
      iconTheme: IconThemeData(color: Colors.white),
      backgroundColor: Color.fromRGBO(64, 153, 255, 1),
      elevation: 0,
      leading: IconButton(
        icon: Icon(Icons.arrow_back),
        onPressed: () {
          Navigator.pop(context);
        },
      ),
    );
  }
}
